package com.template.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.template.entity.Staff;
import com.template.entity.User;
import com.template.mapper.StaffMapper;
import com.template.service.StaffService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yumuyang
 * @since 2021-11-01
 */
@Service
public class StaffServiceImpl extends ServiceImpl<StaffMapper, Staff> implements StaffService {

    @Autowired
    StaffMapper staffMapper;

    public Page<Staff> selectAllPage(Integer pn) {
        Page<Staff> page = new Page<>(pn, 10);
        return staffMapper.selectPage(page, null);
    }

    public Page<Staff> selectAllPageByWrapper(Integer pn, Integer departmentid, String keyword) {
        Page<Staff> staffPage = new Page<>(pn, 10);
        Map<String, Object> params = new HashMap<>();
        params.put("departmentid", departmentid);
        params.put("name", keyword);

        QueryWrapper<Staff> queryWrapper = new QueryWrapper<>();
        queryWrapper.allEq(params, false);
        return staffMapper.selectPage(staffPage, queryWrapper);
    }

    public void deleteStaffById(Integer id) {
        staffMapper.deleteById(id);
    }

    public void saveStaff(Staff staff) {
        staffMapper.insert(staff);
    }

    public void updateStaff(Staff staff) {
        staffMapper.updateById(staff);
    }
}
